import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import s from './s';
import init from '@feidao/web/framework/browser/dn/component';
import fire_component_msg from '@feidao/web/atom/browser/fsm/fire-component-msg';
import nodejs from '@feidao/web/atom/nodejs/msg-b/nodejs';
import render from '@feidao/web/atom/browser/render/render';
import P01 from './P01';
const feidao = {};
let fzno = 0;
const daoke = {
	async init(fd: IFeidaoAiBrowserComponent, ...args: any[]) {

	},
	async eu01(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
		console.log('zj-distribute-list-001 分配学生', args);
		const exam_subjects_id = args[0].currentTarget.dataset.feidaoSubjectsid;
		const class_id = args[0].currentTarget.dataset.feidaoClassid;
		const student_no = args[0].currentTarget.dataset.feidaoStudentno;
		fire_component_msg('zj-distribute-list-002', 'ec01', exam_subjects_id, class_id, student_no);
	},
	async ec02(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
		console.log('zj-distribute-list-001 刷新', args);
		const layout_no = fd.data.params.layout_no || 'BP10020';//todo;
		console.log(layout_no);
		const res = await nodejs("flippedclass", "distribute_list_find", { layout_no });
		render(fd, res, P01, 'P01', 'inner');
	},
	async eu03(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
		console.log('zj-distribute-list-001 清空', args);
		const student_no = args[0].currentTarget.dataset.feidaoStudentno;
		const curr_upd = { student_no, sex: '', student_name: '', student_id: '', student_type: '' };
		const res = await nodejs('flippedclass', 'distribute_student_upd', curr_upd);
		if (res == 'success') {
			fd.fire('ec02');
		} else {
			alert('操作失败');
		}
	},
	async ec04(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
		console.log('zj-distribute-list-001 随机分配', args);
		const class_id = args[0].currentTarget.dataset.feidaoClassid;
		const exam_subjects_id = args[0].currentTarget.dataset.feidaoSubid;
		const layout_no = fd.data.params.layout_no || 'BP10020';//todo
		const res = await nodejs('flippedclass', 'distribute_student_random', { class_id, exam_subjects_id, layout_no });
		if (res == 'success') {
			fd.fire('ec02');
		} else {
			alert('操作失败');
		}
	}
};

const rules = {};

export default function main(url: string, query: any) {
	return init('zj-distribute-list-001', s, rules, feidao, daoke, url, query, { spaceid: 'flippedclass', systemid: '5991', refsystemid: '@refsystemid' });
}
